package com.zuihai.app.mvp.ui.holder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.TimeUtils;
import com.jakewharton.rxbinding.widget.RxTextView;
import com.zuihai.app.R;
import com.zuihai.app.mvp.constant.DetailConstant;
import com.zuihai.app.mvp.model.entity.Detail;

import butterknife.BindView;
import rx.Observable;
import rx.functions.Func1;

/**
 * Created by Administrator on 2017/5/12 0012.
 */

public class DetailPictureRecommentHolder extends BaseViewHolderWraper<Detail.Recommend> {

    @BindView(R.id.tv_title)
    TextView mTitleView;

    @BindView(R.id.tv_auther)
    TextView mAuthorView;

    @BindView(R.id.tv_time)
    TextView mTimeView;

    public DetailPictureRecommentHolder(View itemView) {
        super(itemView);
    }

    @Override
    public void fillData(Detail.Recommend data, int position) {
        super.fillData(data, position);
        ImageView ivCoverOne=getView(R.id.iv_cover);
        ViewGroup.LayoutParams layoutParams = ivCoverOne.getLayoutParams();
        layoutParams.height = (int) (ivCoverOne.getMeasuredWidth() * 0.5625);
        ivCoverOne.setLayoutParams(layoutParams);
        loadImage(R.id.iv_cover, data.picture.get(0).pictureUrl);
        Observable.just(data.title)
                .subscribe(RxTextView.text(mTitleView));
        Observable.just(data.name)
                .subscribe(RxTextView.text(mAuthorView));
        Observable.just(data.time)
                .map(new Func1<Long, String>() {
                    @Override
                    public String call(Long aLong) {
                        return TimeUtils.millis2String(aLong, DetailConstant.DEFAULT_PATTERN);
                    }
                })
                .subscribe(RxTextView.text(mTimeView));
    }
}
